package com.wanjia.bpsapi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wanjia.bpsapi.mapper.VegetableMapper;
import com.wanjia.bpsapi.pojo.dto.VegeName;
import com.wanjia.bpsapi.pojo.entity.Vegetable;
import com.wanjia.bpsapi.pojo.entity.WjStoreProduct;
import com.wanjia.bpsapi.service.IVegetableService;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜品表 服务实现类
 * </p>
 *
 * @author wyn
 * @since 2023-02-13
 */
@Service
public class VegetableServiceImpl extends ServiceImpl<VegetableMapper, Vegetable> implements IVegetableService {

    @Setter(onMethod_ = @Autowired)
    private VegetableMapper mapper;

    @Override
    public List<VegeName> getVegeNames() {
        return mapper.getVegeNames();
    }

    @Override
    public int addVegetable(WjStoreProduct wjStoreProduct) {
        Integer id = wjStoreProduct.getId();
        String storeName = wjStoreProduct.getStoreName();
        Vegetable vegetable = mapper.selectById(id);
        if (vegetable == null){
            mapper.addVegetable(id,storeName);
        }
        return mapper.updateVegetable(id,storeName);
    }
}
